<?php
include_once('kelas/record.php');
include_once('kelas/kategori.php');

include_once('kelas/amankanParam.php');
include_once('kelas/produk.php');
$dtPost = $objParamAman->postMethod();
$dtGet = $objParamAman->getMethod();
$dataPerPage = 9; //limit
$start = isset($dtGet['hal']) ? $dtGet['hal'] : 0;
$sort =array();
if(isset($dtGet['kat'])){$sort['idkategori']=$dtGet['kat'];};
if(isset($dtGet['merk'])){$sort['idmerk']=$dtGet['merk'];};
$strSearch = isset($dtGet['search'])?$dtGet['search']:'';
$dtDisplay = $objProduk->getDisplayProduk($dataPerPage, $start*$dataPerPage, 'nama', 'ASC',$sort,$strSearch);
?>
<link rel="stylesheet" type="text/css" href="css/isi.css" />
<div id="frame_store">
    <div class="frame_menu_kiri_produk">
        <div class="menu_kiri_produk_1">
            <span class="font_judul_2">CATEGORIES</span> <br><br>
            <span class="font_isi_judul">
                <ul style="padding-left:12px;">
                    <?php
                    $strUrlKat = 'index.php?v=store';
                    $strUrlKat .=isset($dtGet['merk'])? "&merk=".$dtGet['merk']:'';                    
                    $dtKat = $objKategori->getDataAktif();
                    $strAdd="style='text-decoration:underline;text-weight:bold;text-decoration:underline;color:red'";
                    ?>
                    <li><a <?php echo isset($dtGet['kat'])?'':$strAdd; ?> 
                        href="<?php echo BASEURL.$strUrlKat; ?>">All Categories</a><br />
                                <span class="font_line">-------------------</span></li>
                    <?php
                    if ($dtKat['success'] == true && $dtKat['total'] > 0) {
                        foreach ($dtKat['result'] as $vK) {
                            $strAdd='';
                            $idKatGet = isset($dtGet['kat'])?$dtGet['kat']:'';
                            if($idKatGet==$vK['id']){
                                $strAdd="style='text-decoration:underline;text-weight:bold;text-decoration:underline;color:red'";
                                $specKat=$vK['nama'];
                            };
                            $jmlBrdsrKat = $objProduk->countBased('idkategori',$vK['id']);
                            if($jmlBrdsrKat>0){
                            ?>
                            <li><a <?php echo $strAdd; ?> href="<?php echo BASEURL.$strUrlKat.'&kat='.$vK['id']; ?>">
                                <?php echo $vK['nama'];echo "&nbsp;(".$jmlBrdsrKat.")" ;?></a> <br />
                                <span class="font_line">-------------------</span></li>
                            <?php
                        }
                        }
                    } else {
                        ?>
                        <li><a href="#">(tidak ada kategori)</a> <br />
                            <span class="font_line">-------------------</span></li>
                        <?php
                    }
                    ?>

                </ul>
            </span>
        </div>

    </div>

    <div class="frame_produk">
        <div class="banner_produk">&nbsp;</div>

        <div class="juduk_page_store">
            <span class="font_judul"><?php if(isset($specKat) || isset($specMerk) || isset($search)){
                $strEc = array();
                if(isset($specKat)){
                    $strEc[]=$specKat;
                };
                if(isset($specMerk)){
                    $strEc[]=$specMerk;
                };
                if(isset($dtGet['search']) && strlen($dtGet['search'])){
                    $strEc[]=' Pencarian : '.$dtGet['search'];
                };

                echo implode(" | ",$strEc);
            }
            else{
                echo 'ALL PRODUCT';
            } ?> <br />
                <span class="font_line">-------------------------------------------------------------------------------------</span>

            </span>
        </div>
        <div class="page-produk">
            <?php 

                    $strUrlBuatHal = '&v=store';
                    $strUrlBuatHal .= isset($dtGet['search'])?'&search='.$dtGet['search']:'';
                    $strUrlBuatHal .=isset($dtGet['kat'])? "&kat=".$dtGet['kat']:'';
                    

            echo $objFungsi->buatHalaman($dtDisplay['total'], $dataPerPage, $start, $strUrlBuatHal); ?>
        </div>
        <div class="frame_list_produk">
            <?php
            //echo $objProduk->strQuery;
            //$objFungsi->var_dump($dtDisplay);
            if ($dtDisplay['total'] > 0) {
                $strSrch = isset($dtGet['search'])?$dtGet['search']:'';
                foreach ($dtDisplay['result'] as $Ldisp) {
                    ?>
                    <div class="list_produk">
                        <table width="190" cellpadding="3" cellspacing="0" border="0">
                            <tr>
                                <td colspan="2" valign="middle" align="center">
                                    <a href="<?php echo BASEURL.'index.php?v=detail&id='.$Ldisp['id'] ?>" >
                                    <img class="display-produk" src="produk/<?php echo $Ldisp['gambar']; ?>" width="180" height="180" />
                                    </a>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" class="font_sub_judul">
                                    <?php echo str_ireplace(isset($strSrch) && strlen($strSrch)>0?$strSrch:'', "<span style='font-weight:bold;text-decoration:underline;color:red'>".$strSrch."</span>",$Ldisp['nama']); ?></td>
                            </tr>

                            <tr>
                                <td class="font_sub_judul">Kategori</td><td><?php echo str_ireplace(isset($strSrch) && strlen($strSrch)>0?$strSrch:'', "<span style='font-weight:bold;text-decoration:underline;color:red'>".$strSrch."</span>",$Ldisp['nama_kategori']); ?></td>
                                
                            </tr>
                            <tr>
                                <td colspan="2" valign="top" class="font_isi_judul"><?php $subStrKeterangan = strlen($Ldisp['keterangan'])>60?substr($Ldisp['keterangan'],0,57)."...":$Ldisp['keterangan'];echo (strlen($strSrch)>0)?str_ireplace($strSrch,"<span style='font-weight:bold;text-decoration:underline;color:red'>".$strSrch."</span>",$subStrKeterangan):$subStrKeterangan;  ?></td>
                            </tr>
                            <tr>
                                <td colspan="2"><?php $hJ = ($Ldisp['diskon']>0)?(int)$Ldisp['harga_jual']-((int) $Ldisp['harga_jual']*((int) $Ldisp['diskon']/100)):(int) $Ldisp['harga_jual']; echo 'Rp. ' . number_format($hJ, 0, '.', ','); ?></td>
                            </tr>
                            <tr>
                                <td width="108" class="font_isi_judul"><?php echo  $Ldisp['diskon']<1?'':'<span style="text-decoration:line-through;color:red">Rp. ' . number_format((int) $Ldisp['harga_jual'], 0, '.', ',').'</span>'; ?></td>
                                <td width="80" align="right"><a href="<?php echo BASEURL.'proses/belanja.php?on=addCart&id='.$Ldisp['id']; ?>"><div class="button">add to cart</div></a></td>
                            </tr>
                        </table>
                    </div>
                    <?php
                }
            }
            ?> 
        </div>
    </div>
</div>